package com.example.zhinongbao.ui;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.zhinongbao.R;
import com.example.zhinongbao.utils.FragmentUtils;
import com.example.zhinongbao.utils.ToastUtils;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

/**
 * 主页activity
 */
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 初始化ToastUtils
        ToastUtils.getInstance().init(this);
        // 初始化FragmentUtils
        FragmentUtils.getInstance().init(getSupportFragmentManager());
        // 加载首页Fragment
        FragmentUtils.getInstance().switchFragment(R.id.nav_home);
        // 加载底部导航栏
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
        bottomNavigationView.setItemIconTintList(null);
        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                FragmentUtils.getInstance().switchFragment(item.getItemId());
                return true;
            }
        });
    }

}
